
<div class="span12">
    <div class="box box-color box-bordered">
        <div class="box-title">
            <h3>
                <i class="icon-table"></i>
                Locales
            </h3>
            <div class="actions">
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_ORDER'))) { ?>
                    <a href="#mdlOrder" role="button" class="btn" data-toggle="modal"><i class="icon-table"></i></a>
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_FILTER'))) { ?>
                    <a href="#mdlFilter" role="button" class="btn" data-toggle="modal"><i class="icon-search"></i></a>
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_EXCEL'))) { ?>
                    <a href="<?php echo url_for('/stores/excelStores');?>" role="button" class="btn" ><i class="icon-download-alt"></i></a>
                <?php } ?>
              
            </div>
        </div>
        <div class="box-content nopadding">
            
            <?php //echo $userOrderCount;die();
            
            if($userOrderCount !=0){
            ?>
            <table class="table table-bordered dataTable dataTable-scroll-x">
                <thead>
                    <tr>
                        <?php 
                        foreach ($userTableOrder as $value) {?>
                            
                       
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==1 && $value['UserTableOrder'][0]['visible']==1){?><th>Canal</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==2 && $value['UserTableOrder'][0]['visible']==1){?><th>Cliente</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==3 && $value['UserTableOrder'][0]['visible']==1){?><th>Cadena / Formato</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==4 && $value['UserTableOrder'][0]['visible']==1){?><th>Cód. Formato</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==5 && $value['UserTableOrder'][0]['visible']==1){?><th>Concesión</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==6 && $value['UserTableOrder'][0]['visible']==1){?><th>Ubicación</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==7 && $value['UserTableOrder'][0]['visible']==1){?><th>Cód. Proveedor</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==8 && $value['UserTableOrder'][0]['visible']==1){?><th>Cód. Local</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==9 && $value['UserTableOrder'][0]['visible']==1){?><th>Cód. RB</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==10 && $value['UserTableOrder'][0]['visible']==1){?><th>Nombre</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==11 && $value['UserTableOrder'][0]['visible']==1){?><th>Dirección</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==12 && $value['UserTableOrder'][0]['visible']==1){?><th>Comuna</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==13 && $value['UserTableOrder'][0]['visible']==1){?><th>Provincia</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==14 && $value['UserTableOrder'][0]['visible']==1){?><th>Región</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==15 && $value['UserTableOrder'][0]['visible']==1){?><th>País</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==16 && $value['UserTableOrder'][0]['visible']==1){?><th>Superficie</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==17 && $value['UserTableOrder'][0]['visible']==1){?><th>Cluster</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==18 && $value['UserTableOrder'][0]['visible']==1){?><th>Responsable1</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==19 && $value['UserTableOrder'][0]['visible']==1){?><th>Responsable2</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==20 && $value['UserTableOrder'][0]['visible']==1){?><th>Responsable3</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==21 && $value['UserTableOrder'][0]['visible']==1){?><th>Gerente</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==22 && $value['UserTableOrder'][0]['visible']==1){?><th>Administrador</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==23 && $value['UserTableOrder'][0]['visible']==1){?><th>Vta. Promedio</th><?php }?>
                        
                        
                        <?php }?>
                    </tr>
                </thead>
                <tbody>
                    
                        <?php
                        $dataArray = array();
                        $i = 0;
                        foreach ($stores as $value) {

                            $dataArray[$i][]['Channels'] = $value['Channels']['name'];
                            $dataArray[$i][]['Customers'] = $value['Customers']['name'];
                            $dataArray[$i][]['Formats'] = $value['Formats']['name'];
                            $dataArray[$i][]['CodeFormats'] = $value['CodeFormats']['name'];
                            $dataArray[$i][]['Concessions'] = $value['Concessions']['name'];
                            $dataArray[$i][]['Location'] = $value['Locations']['name'];
                            $dataArray[$i][]['code_supplier'] = $value['code_supplier'];
                            $dataArray[$i][]['code_store'] = $value['code_store'];
                            $dataArray[$i][]['id_store'] = $value['id_store'];
                            $dataArray[$i][]['name'] = $value['name'];
                            $dataArray[$i][]['address'] = $value['address'];
                            $dataArray[$i][]['Comunas'] = $value['Comunas']['name'];
                            $dataArray[$i][]['Provincias'] = $value['Provincias']['name'];
                            $dataArray[$i][]['Regiones'] = $value['Regiones']['name'];
                            $dataArray[$i][]['Paises'] = $value['Paises']['name'];
                            $dataArray[$i][]['sourface'] = $value['sourface'];
                            $dataArray[$i][]['Clusters'] = $value['Clusters']['name'];
                            $dataArray[$i][]['responsiblea'] = $value['responsiblea'];
                            $dataArray[$i][]['responsibleb'] = $value['responsibleb'];
                            $dataArray[$i][]['responsiblec'] = $value['responsiblec'];
                            $dataArray[$i][]['manager'] = $value['manager'];
                            $dataArray[$i][]['administrator'] = $value['administrator'];
                            $dataArray[$i][]['averange_sales'] = $value['averange_sales'];
                            $i++;
                        }


                        for ($x = 0; $x < $i; $x++) {
                            ?>
                            <tr>

                                        <?php foreach ($userTableOrder as $value) { ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 1 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][0]['Channels']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 2 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][1]['Customers']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 3 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][2]['Formats']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 4 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][3]['CodeFormats']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 5 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][4]['Concessions']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 6 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][5]['Locations']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 7 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][6]['code_supplier']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 8 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][7]['code_store']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 9 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][8]['id_store']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 10 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][9]['name']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 11 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][10]['address']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 12 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][11]['Comunas']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 13 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][12]['Provincias']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 14 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][13]['Regiones']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 15 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][14]['Paises']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 16 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][15]['surface']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 17 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][16]['Clusters']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 18 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][17]['responsiblea']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 19 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][18]['responsibleb']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 20 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][19]['responsiblec']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 21 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][20]['manager']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 22 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][21]['administrator']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 23 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][22]['average_sales']; ?></td><?php } ?>
                                        <?php }
                                        ?>
                            </tr>
                            <?php
                        }
                        ?>

                </tbody>
            </table>
            
            <?php }else{ ?>  
            
            <table class="table table-bordered dataTable dataTable-scroll-x">
                <thead>
                    <tr>
                        <th>Canal</th>
                        <th>Cliente</th>
                        <th>Cadena / Formato</th>
                        <th>Cód. Formato</th>
                        <th>Concesión</th>
                        <th>Ubicación</th>
                        <th>Cód. Proveedor</th>
                        <th>Cód. Local</th>
                        <th>Cód. RB</th>
                        <th>Nombre</th>
                        <th>Dirección</th>
                        <th>Comuna</th>
                        <th>Provincia</th>
                        <th>Región</th>
                        <th>País</th>
                        <th>Superficie</th>
                        <th>Cluster</th>
                        <th>Responsable1</th>
                        <th>Responsable2</th>
                        <th>Responsable3</th>
                        <th>Gerente</th>
                        <th>Administrador</th>
                        <th>Vta. Promedio</th>
                    </tr>
                </thead>
                <tbody>
                        
                    <?php foreach ($stores as $value) { ?>

                        <tr>
                            <td><?php echo $value['Channels']['name']; ?></td>
                            <td><?php echo $value['Customers']['name']; ?></td>
                            <td><?php echo $value['Formats']['name']; ?></td>
                            <td><?php echo $value['CodeFormats']['name']; ?></td>
                            <td><?php echo $value['Concessions']['name']; ?></td>
                            <td><?php echo $value['Locations']['name']; ?></td>
                            <td><?php echo $value['code_supplier'];?></td>
                            <td><?php echo $value['code_store'];?></td>
                            <td><?php echo $value['id_store'];?></td>
                            <td><?php echo $value['name'];?></td>
                            <td><?php echo $value['address'];?></td>
                            <td><?php echo $value['Comunas']['name']; ?></td>
                            <td><?php echo $value['Provincias']['name']; ?></td>
                            <td><?php echo $value['Regiones']['name']; ?></td>
                            <td><?php echo $value['Paises']['name']; ?></td>
                            <td><?php echo $value['surface'];?></td>
                            <td><?php echo $value['Clusters']['name']; ?></td>
                            <td><?php echo $value['responsiblea'];?></td>
                            <td><?php echo $value['responsibleb'];?></td>
                            <td><?php echo $value['responsiblec'];?></td>
                            <td><?php echo $value['manager'];?></td>
                            <td><?php echo $value['administrator'];?></td>
                            <td><?php echo $value['average_sales'];?></td>
                        </tr>
                    <?php } ?>

                </tbody>
            </table>
            
            
            <?php }?>
        </div>
    </div>
</div>